package com.sf.proxy.handler;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.DatagramPacket;

import java.nio.charset.StandardCharsets;


public class UdpPacketHandler extends SimpleChannelInboundHandler<DatagramPacket> {


    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, DatagramPacket datagramPacket) {
        System.out.println("receive packet " + datagramPacket.content().toString(StandardCharsets.UTF_8));
        channelHandlerContext.writeAndFlush(new DatagramPacket(Unpooled.copiedBuffer("hello world".getBytes(StandardCharsets.UTF_8)), datagramPacket.sender()));
    }
}
